package model;

import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.Signature;

public class CSR {

	private String commonName;
	private String organization;
	private String organizationalUnit;
	private String locality;
	private String state;
	private String country;
	private String email;

	private Signature signature;
	private String signatureAlgorithm;
	private String keyAlgorith;
	private int keyLength;

	private PublicKey publickey;
	private PrivateKey priavteKey;

	// setters and getters

	
	public PublicKey getPublickey() {
		return publickey;
	}

	public void setPublickey(PublicKey publickey) {
		this.publickey = publickey;
	}

	public PrivateKey getPriavteKey() {
		return priavteKey;
	}

	public void setPriavteKey(PrivateKey priavteKey) {
		this.priavteKey = priavteKey;
	}

	public String getCommonName() {
		return commonName;
	}

	public void setCommonName(String commonName) {
		this.commonName = commonName;
	}

	public String getOrganization() {
		return organization;
	}

	public void setOrganization(String organization) {
		this.organization = organization;
	}

	public String getOrganizationalUnit() {
		return organizationalUnit;
	}

	public void setOrganizationalUnit(String organizationalUnit) {
		this.organizationalUnit = organizationalUnit;
	}

	public String getLocality() {
		return locality;
	}

	public void setLocality(String locality) {
		this.locality = locality;
	}

	public String getState() {
		return state;
	}

	public void setState(String state) {
		this.state = state;
	}

	public String getCountry() {
		return country;
	}

	public void setCountry(String country) {
		this.country = country;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public Signature getSignature() {
		return signature;
	}

	public void setSignature(Signature signature) {
		this.signature = signature;
	}

	public String getSignatureAlgorithm() {
		return signatureAlgorithm;
	}

	public void setSignatureAlgorithm(String signatureAlgorithm) {
		this.signatureAlgorithm = signatureAlgorithm;
	}

	public String getKeyAlgorith() {
		return keyAlgorith;
	}

	public void setKeyAlgorith(String keyAlgorith) {
		this.keyAlgorith = keyAlgorith;
	}

	public int getKeyLength() {
		return keyLength;
	}

	public void setKeyLength(int keyLength) {
		this.keyLength = keyLength;
	}

	// intialize csr values
	public CSR(String commonName, String organization,
			String organizationalUnit, String locality, String state,
			String country, String email) {
		super();
		this.commonName = commonName;
		this.organization = organization;
		this.organizationalUnit = organizationalUnit;
		this.locality = locality;
		this.state = state;
		this.country = country;
		this.email = email;
	}

	public void initSignature() {
		try {
			this.signature = Signature.getInstance(this.signatureAlgorithm);
			this.signature.initSign(this.priavteKey);
		} catch (InvalidKeyException | NoSuchAlgorithmException n) {

		}
	}
}
